package com.fr.schedule.output;

import com.fr.base.FRContext;
import com.fr.base.XMLable;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.DateUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.dav.Env;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import java.io.File;
import java.text.DateFormat;
import java.util.Date;

public class FileRepository
  implements XMLable
{
  public static final String XML_TAG = "FileRepository";
  private String path = null;

  public FileRepository()
  {
    if (FRContext.getCurrentEnv() != null)
      setPath(FRContext.getCurrentEnv().getPath() + File.separator + "schedule");
  }

  public FileRepository(String paramString)
  {
    this.path = paramString;
  }

  public JSONObject createJSONConfig()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("path", getPath());
    return localJSONObject;
  }

  public static FileRepository analyzeJSON(JSONObject paramJSONObject)
  {
    String str;
    try
    {
      str = paramJSONObject.getString("path");
      return new FileRepository(str);
    }
    catch (JSONException localJSONException)
    {
      localJSONException.printStackTrace();
    }
    return null;
  }

  public void setPath(String paramString)
  {
    this.path = paramString;
  }

  public String getPath()
  {
    return this.path;
  }

  public File getTaskDirFile(String paramString)
  {
    return new File(getPath(), paramString);
  }

  public File getTaskTimeDirFile(String paramString, Date paramDate)
  {
    String str = DateUtils.TIMEFORMAT.format(paramDate).replaceAll(":", "");
    return new File(getTaskDirFile(paramString + File.separator + DateUtils.DATEFORMAT2.format(paramDate)), str.substring(0, str.length() - 2));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      String str;
      if ((str = paramXMLableReader.getAttr("path")) != null)
        setPath(str);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("FileRepository").attr("path", this.path).end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof FileRepository))
      return false;
    FileRepository localFileRepository = (FileRepository)paramObject;
    return ComparatorUtils.equals(localFileRepository.getPath(), getPath());
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    FileRepository localFileRepository = (FileRepository)super.clone();
    return localFileRepository;
  }
}